<template>
  <div>
    <el-table :data="bannerArr" border style="width: 791px">
      <el-table-column type="index" label="编号"
                       width="140" align="center"></el-table-column>
      <el-table-column label="轮播图" width="500" align="center">
        <template slot-scope="scope">
          <!--scope.row代表当前遍历的数组中的对象-->
          <img :src="scope.row.url" width="150">
        </template>
      </el-table-column>
      <!--*******************************-->
      <el-table-column label="操作" width="150" align="center">
        <!--scope代表每行对应的数据里面的index属性代表下标,
        里面的row代表每行对应的数组中的对象-->
        <template slot-scope="scope">
          <!--confirm确认事件-->
          <el-popconfirm @confirm="bannerDelete(scope.$index, scope.row)"
                         title="这是一段内容确定删除吗？">
            <el-button size="mini"
                       type="danger" slot="reference">删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
      <!--*******************************-->
    </el-table>
  </div>

</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      bannerArr:[]
    }
  },
  created() {
    let url = 'http://localhost:8080/banners/getBanner'
    axios.get(url).then((response) => {
      let json = response.data
      if (json.state==20000) {
        console.log(json.data)
        this.bannerArr = json.data
      }
    })
  },
  methods: {
    bannerDelete(index,banner){
      let url = 'http://localhost:8080/banners/delete/'+banner.id
      axios.get(url).then(()=> {
        this.bannerArr.splice(index,1)
      })
    },
  }
}
</script>

<style scoped>

</style>